<?php

namespace app\admin\controller\cms;

use app\admin\controller\AdminController;
use app\admin\service\cms\ArticleCateService;
use app\admin\validate\cms\ArticleCateValidate;
use think\response\Json;

/**
 * 文章栏目控制器
 */
class ArticleCate extends AdminController
{

    /**
     * 查看文章栏目列表
     * @return Json
     */
    public function lists()
    {
        return $this->data(ArticleCateService::getList());
    }

    /**
     * 添加文章栏目
     * @return Json
     */
    public function add()
    {
        $params = (new ArticleCateValidate())->post()->checkParam('add');
        $result = ArticleCateService::add($params);
        if(true === $result) {
            return $this->success([], '添加成功');
        } else {
            return $this->error(ArticleCateService::getError());
        }
    }

    /**
     * 编辑文章栏目
     * @return Json
     */
    public function edit()
    {
        $params = (new ArticleCateValidate())->post()->checkParam('edit');
        $result = ArticleCateService::edit($params);
        if (true === $result) {
            return $this->success([],'编辑成功');
        } else {
            return $this->error(ArticleCateService::getError());
        }
    }

    /**
     * 删除文章栏目
     * @return Json
     */
    public function delete()
    {
        $params = (new ArticleCateValidate())->delete()->checkParam('delete');
        $result = ArticleCateService::delete($params);
        if (true === $result) {
            return $this->success([],'删除成功');
        } else {
            return $this->error(ArticleCateService::getError());
        }
    }

    /**
     * 文章栏目详情
     * @return Json
     */
    public function detail()
    {
        $params = (new ArticleCateValidate())->checkParam('detail');
        $result = ArticleCateService::detail($params);
        return $this->data($result);
    }

    /**
     * 获取文章栏目
     * @return Json
     */
    public function all()
    {
        $result = ArticleCateService::getAllData();
        return $this->data($result);
    }
}